﻿//圈子模块
DaAn.Circle = {
    //ajax 请求路劲后缀
    Url: {
        Jion: "joinCircle",
        Exit: "joinCircle",
        Dismiss: "dismissCircle",
        Reply: "publishReply",
        DeleteReply: "deleteComment",
        EditQuestion: "editQuestion",
        CheckName: "GetCreateCircle",
        Search: "GetCircleList",
        SearchByTag: "GetCircleListTag",
        GetTagListByCategoryId: "GetTagListByCategoryId",
        AddAttention: "AddAttention"
    },
    GetUrl: function (url) {
        return DaAn.Http.AddRandomNumber("/Services/AjaxHandler.ashx?action=Circle." + url);
    },
    Join: function (type, circleID, content, callback) {
        /// <summary>
        /// 加入圈子
        /// </summary>
        /// <param name="type">  
        ///  加入类型：1、直接加入  2、审核验证加入
        /// </param> 
        /// <param name="circleID"> 
        ///  圈子ID
        /// </param> 
        /// <param name="content"> 
        ///  审核内容
        /// </param> 
        var data = type == 1 ? { cid: circleID} : { cid: circleID, con: content };
        DaAn.Ajax(this.GetUrl(this.Url.Jion), data,
            function (result) {
                InvokeCallback(result, callback);
            },
            { type: "post" });
    },
    Exit: function (circleID, callback) {
        /// <summary>
        /// 退出圈子
        /// </summary>
        /// <param name="circleID"> 
        ///  圈子ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.Exit), { circleid: circleID }, function (result) {
            InvokeCallback(result, callback);
        }, { type: "post" });
    },
    Dismiss: function (circleID, callback) {
        /// <summary>
        /// 解散圈子
        /// </summary>
        /// <param name="circleID"> 
        /// 圈子ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.Dismiss), { circleid: circleID }, function (result) {
            InvokeCallback(result, callback);
        }, { type: "post" });
    },
    Reply: function (title, content, circleID, questionID, callback) {
        /// <summary>
        /// 回复帖子
        /// </summary>
        /// <param name="title"> 
        ///  帖子内容
        /// </param> 
        /// <param name="content"> 
        ///  回复内容
        /// </param> 
        /// <param name="circleID"> 
        ///  圈子ID
        /// </param> 
        /// <param name="questionID"> 
        ///  问题ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.Reply),
            { t: title, content: content, circleid: circleID, questionid: questionID },
            function (result) {
                InvokeCallback(result, callback);
            }, { type: "post" });
    },
    DeleteReply: function (ReplyId, callback) {
        /// <summary>
        /// 删除回复
        /// </summary>
        /// <param name="ReplyId"> 
        ///  回复ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.DeleteReply), { ReplyId: ReplyId },
            function (result) {
                InvokeCallback(result, callback);
            }, { type: "post" });
    },
    EditQuestion: function (userid, edittitle, questionid, callback) {
        /// <summary>
        /// 提问编辑（只有身份为医生并且是医生本人的回复）
        /// </summary>
        /// <param name="userid
        /// </param> 
        ///  用户ID
        /// </param> 
        /// <param name="edittitle"> 
        ///  编辑内容
        /// <param name="questionid"> 
        ///  帖子ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.EditQuestion),
            { userid: userid, title: edittitle, questionid: questionid },
            function (result) {
                InvokeCallback(result, callback);
            }, { type: "post" });
    },
    CheckName: function (name, oldName, userid, callback) {
        /// <summary>
        /// 验证圈子名称
        /// </summary>
        /// <param name="name"> 
        ///  圈子名称 
        /// </param> 
        /// <param name="oldName"> 
        ///  当前圈子名字
        /// </param> 
        /// <param name="userid"> 
        ///  用户ID
        /// </param> 
        DaAn.Ajax(this.GetUrl(this.Url.CheckName), { uid: userid, name: name },
            function (result) {
                InvokeCallback(result, callback);
            }, { type: "post" });
    },

    Search: function (data, callback) {
        /// <summary>
        /// 热门圈子分页
        /// </summary>
        /// <param name="data"> 
        ///  分页参数 
        /// </param> 
        var defaults = { key: "", tagName: "", pageIndex: 1, pageSize: 12 };
        DaAn.Ajax(this.GetUrl(this.Url.Search), $.extend(defaults, data || {}),
            function (result) {
                InvokeCallback(result, callback);
            },
            { type: "post" });
    },
    SearchByTag: function (data, callback) {
        /// <summary>
        /// 热门圈子分页
        /// </summary>
        /// <param name="data"> 
        ///  分页参数 keyword orderBy categoryId tagId  pageIndex 
        /// </param> 
        var defaults = { keyword: "", orderBy: "", categoryId: -1, tagId: -1, pageIndex: 0, pageSize: 1, type: "" };
        DaAn.Ajax(
            this.GetUrl(this.Url.SearchByTag),
            $.extend(defaults, data || {}),
            function (result) {
                InvokeCallback(result, callback);
            },
            { type: "post" });
    },
    GetTagListByCategoryId: function (categoryId, callback) {
        /// <summary>
        /// 根据分类id获取该类别下的标签
        /// </summary>
        /// <param name="categoryId"> 
        ///  分类id
        /// </param> 
        DaAn.Ajax(
            this.GetUrl(this.Url.GetTagListByCategoryId), { categoryId: categoryId },
            function (result) {
                InvokeCallback(result, callback);
            },
            { type: "post" });
    },
    AddAttention: function (objId, callback) {
        /// <summary>
        /// 加关注
        /// </summary>
        /// <param name="objId"> 
        ///  分页参数 关注对象ID
        /// </param> 
        DaAn.Ajax(
            this.GetUrl(this.Url.AddAttention), { ObjId: objId },
            function (result) {
                InvokeCallback(result, callback);
            },
            { type: "post" });
      }


}
